Skip to content

feat: support scoped form instance#660

Open
lemonied wants to merge 1 commit intoreact-component:masterfrom
lemonied:feat-scopedForm
Open

feat: support scoped form instance#660
lemonied wants to merge 1 commit intoreact-component:masterfrom
lemonied:feat-scopedForm

Conversation

@lemonied
Copy link
Copy Markdown
Contributor

@lemonied lemonied commented Mar 11, 2024

  • add hook Form.useFormInstance
  • Form.useWatch add param "scoped: true"

ant-design/ant-design#47328

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
field-form ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2024 4:01pm

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.47%. Comparing base (8268294) to head (8607178).
⚠️ Report is 84 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #660      +/-   ##
==========================================
+ Coverage   99.43%   99.47%   +0.03%     
==========================================
  Files          18       19       +1     
  Lines        1247     1335      +88     
  Branches      288      308      +20     
==========================================
+ Hits         1240     1328      +88     
  Misses          7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

import * as React from 'react';
import type { InternalFormInstance } from './interface';

const FormInstanceContext = React.createContext<InternalFormInstance | undefined>(undefined);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能复用 Context 不,List 其实也是加了一个 Scope 理论上来说不用新加一个

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复用FieldContext的话,会造成一个问题:
在子组件里拿到的FormInstance不等于最顶层的Form.useForm()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

想了一下,确实可以用FieldContext传递FormInstance,已修改 @zombieJ

- add hook Form.useFormInstance
- Form.useWatch add param "scoped: true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants